package io.gitee.yth.design.pattern.test.core.pattern.structural.composite.code;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yth
 * @since 2023-04-26-21:21
 */
public class College extends Organization {
    private final List<Department> components = new ArrayList<>();

    public College(String name) {
        this.name = name;
        this.description = "college";
    }

    @Override
    public void printAll() {
        System.out.println("----------College----------");
        System.out.println(name);
        components.forEach(Organization::printAll);
        System.out.println("----------End----------");
    }

    @Override
    protected void add(Organization organization) {
        if (!(organization instanceof Department)) {
            throw new IllegalArgumentException();
        }
        components.add((Department) organization);
    }

    @Override
    protected void remove(Organization organization) {
        if (!(organization instanceof Department)) {
            throw new IllegalArgumentException();
        }
        components.remove(organization);
    }

    @Override
    protected Department getChild(int i) {
        return components.get(i);
    }
}
